/*
 * @Author: yangni 920556271@qq.com
 * @Date: 2023-12-10 12:14:27
 * @LastEditors: yangni 920556271@qq.com
 * @LastEditTime: 2024-04-21 11:35:50
 * @FilePath: /yt-devops/lib/pages/devices/device_tab/device_detail/battery_cell_tree/battery_cell_tree_view.dart
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import 'package:bruno/bruno.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:yt_devops/components/app_bar/app_bar_widget.dart';
import 'package:yt_devops/components/brn/brn_expandable_group_with_operate.dart';
import 'package:yt_devops/components/yt_expandable_tree/yt_expandable_tree.dart';
import 'package:yt_devops/resources/str_res_keys.dart';
import 'package:yt_devops/styles/styles.dart';
import 'battery_cell_tree_controller.dart';
import 'battery_cell_tree_model.dart';

class BatteryCellTreePage extends GetView<BatteryCellTreeController> {
  const BatteryCellTreePage({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBarWidget.defaultAppBar(ResKey.deviceChooseCluster.tr),
      body: GetBuilder<BatteryCellTreeController>(
        builder: (controller) => SafeArea(
          child: Container(
            color: Colour.white,
            padding: EdgeInsets.symmetric(horizontal: 16.w),
            child: YtExpandableTree(
              multiple: false,
              checkedValues: [controller.selectedValue?.deviceId],
              treeData: controller.treeNode,
              onValueChanged: (newVal) {
                if (controller.isLocked) {
                  return;
                }
                if (newVal.isNotEmpty) {
                  controller.selected(newVal[0]);
                } else {
                  Get.back<BatteryCellTreeModel>(
                      result: controller.selectedValue);
                }
              },
            ),
          ),
        ),
      ),
    );
  }
}
